package off_trial

import (
	"bp/internal/render"
	"bp/internal/util"
	offTrialGrpc "bp/rpc/gen/mwebapi/off_trial"
	"context"
)

// 获取优惠试算信息
func (s *OffTrialMWebApiImp) GetOffTrialInfo(ctx context.Context, req *offTrialGrpc.GetOffTrialInfoReq) (res *offTrialGrpc.GetOffTrialInfoRes, err error) {
	slog := util.NewContextLogger(ctx, s.slog)
	slog.Infof("offer_trial_imp/query.GetOffTrialInfo=>%+v", req)
	defer render.FriendlyEntityError(&err, EntityName)
	res = &offTrialGrpc.GetOffTrialInfoRes{}
	q := s.dao.Q

	ptr, err := s.VldGetOffTrialInfoReq(ctx, q, req)
	if err != nil {
		return
	}
	off, trialedOwnerPtrs, trialedOfferItemPtrOfCardDiscount, err := s.comHub.OfferService.GetTrialInfo(ctx, q, ptr)
	if err != nil {
		return
	}

	res.Off = off
	res.Owners = s.ConvOffTrialOwnerPtrArrayEntityToPb()(trialedOwnerPtrs)
	res.CardDiscount = s.ConvOffTrialOfferItemPtrEntityToPb()(trialedOfferItemPtrOfCardDiscount)
	return
}
